<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="projetCalendar.Model.Evenement"%>
<%@ page import="java.util.List" %>
<%@page import="java.util.Calendar" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
   SimpleDateFormat sdf_sortie = new SimpleDateFormat("EEEE dd MMMM yyyy");
   SimpleDateFormat sdf_heure = new SimpleDateFormat("HH:mm");
    SimpleDateFormat sdf_param = new SimpleDateFormat("yyyy-MM-dd HH:mm");
   Date date = (Date)request.getAttribute("datesemaine");
   Calendar dayWeek = Calendar.getInstance();
   dayWeek.setTime(date);
   List<Evenement> evenements = (List<Evenement>)request.getAttribute("evenements");
   Evenement event = null;
%>

<script type="text/javascript">
    mode = "semaine";
</script>
<div id="calendrierSemaines">
    
<table>
    <thead>
    
   
   <tr>
       <th rowspan="2"/>
       <!-- ligne -->
                 <% for (int i = 0; i < 7; i++) {%>
       <!--<td>&nbsp;</td> -->
       <th id="jourActuel" colspan="35" ><%= sdf_sortie.format(dayWeek.getTime())%></th>
       <%dayWeek.add(Calendar.DAY_OF_WEEK, +1);%>
       <% }%>
       <% dayWeek.setTime(date);%>
   </tr>
                
              
    </thead>
    
    <tbody>
        
        <%for (int i = 0; i < 24; i++) {%>
            
        <% dayWeek.set(Calendar.HOUR_OF_DAY, i);%>
        <% dayWeek.set(Calendar.MINUTE, 0);%>
            
        <tr class="heure">
            
        <th rowspan="2"><%=sdf_heure.format(dayWeek.getTime())%></th>
            
        <%for (int j = 0; j < 7; j++) {%>
        <% event = Evenement.getEvenementHeure(dayWeek, evenements);%>
            
        <% if (event == null) {%>
        <td class="heure_<%= dayWeek.getTimeInMillis()%>" colspan="35">
            
            <% if (Evenement.estDispo(dayWeek, evenements, Evenement.DUREE_PAR_DEFAUT)) {%> 
            <a
                class="addEventLink"
                href="<%=getServletContext().getContextPath()%>/evenements/nouveau?date=<%=sdf_param.format(dayWeek.getTime())%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                onclick="evenement.newEvent(<%= dayWeek.getTimeInMillis()%>)">&nbsp;</a>
            <% }%>
                
        </td>
            
            
        <% } else if (event.getDateDebut().getTime() == dayWeek.getTimeInMillis()) {%>  
        <td id="heure_<%= dayWeek.getTimeInMillis()%>" class="evenement" rowspan="<%=event.getDuree() * 2%>">
            <%=event.getObjet()%>
            <a
                href="<%=getServletContext().getContextPath()%>/evenements/afficher?id=<%=event.getId()%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                onclick="">afficher</a>
            <a
                href="<%=getServletContext().getContextPath()%>/evenements/editer?id=<%=event.getId()%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                onclick="return true;//new Ajax.Request('<%=getServletContext().getContextPath()%>/evenements/editer', {evalScript: true, parameters: {id :'<%=event.getId()%>'}});return false;">editer</a>
            <a
                href="<%=getServletContext().getContextPath()%>/evenements/supprimer?id=<%=event.getId()%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                onclick="">effacer</a>
        </td>
                        
        <% }%>
        
        <%dayWeek.add(Calendar.DAY_OF_WEEK, +1);%>
        
        <% }%>
        </tr>
        
        <% dayWeek.setTime(date);%>
        <% dayWeek.set(Calendar.HOUR_OF_DAY, i);%>
        <% dayWeek.set(Calendar.MINUTE, 30);%>
            
        <tr class="demi-heure">
            <% for (int k = 0; k < 7; k++) {%>
            <% event = Evenement.getEvenementHeure(dayWeek, evenements);%>
            <% if (event == null) {%>
            <td id="heure_<%= dayWeek.getTimeInMillis()%>" colspan="35">
                <% if (Evenement.estDispo(dayWeek, evenements, Evenement.DUREE_PAR_DEFAUT)) {%> 
                <a
                    class="addEventLink"
                    href="<%=getServletContext().getContextPath()%>/evenements/nouveau?date=<%=sdf_param.format(dayWeek.getTime())%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                    onclick="evenement.newEvent(<%= dayWeek.getTimeInMillis()%>)">&nbsp;</a>
               <% } %>
            </td>
                
            <% } else if (event.getDateDebut().getTime() == dayWeek.getTimeInMillis()) {%>
            <td id="heure_<%= dayWeek.getTimeInMillis()%>" class="evenement" 
                rowspan="<%=event.getDuree() * 2%>">
                <%=event.getObjet()%>
                <a
                    
                    href="<%=getServletContext().getContextPath()%>/evenements/afficher?id=<%=event.getId()%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                    onclick="">afficher</a>
                <a
                    
                    href="<%=getServletContext().getContextPath()%>/evenements/editer?id=<%=event.getId()%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                    onclick="">editer</a>
                <a
                    
                    href="<%=getServletContext().getContextPath()%>/evenements/supprimer?id=<%=event.getId()%>&retour=<%=getServletContext().getContextPath()%>/semaine"
                    onclick="">effacer</a>
            </td>
                
            <% }%>
            <%dayWeek.add(Calendar.DAY_OF_WEEK, +1);%>
            <% }%>  
        </tr>
        <% dayWeek.setTime(date);%>
            
        <% }%>        
    </tbody>
</table>    
</div>
    